{% extends "admin/base.html" %}

{% block title %}网站设置 - 万岛潜水管理后台{% endblock %}

{% block page_title %}网站设置{% endblock %}

{% block content %}
<div class="row">
    <div class="col-md-6">
        <div class="card mb-4">
            <div class="card-header">
                <h5 class="mb-0">基本信息设置</h5>
            </div>
            <div class="card-body">
                <form method="post" action="{{ url_for('main.admin_update_settings') }}" enctype="multipart/form-data">
                    <div class="mb-3">
                        <label for="site_name" class="form-label">网站名称</label>
                        <input type="text" class="form-control" id="site_name" name="site_name" value="{{ settings.site_name if settings else '万岛潜水' }}" required>
                    </div>
                    <div class="mb-3">
                        <label for="site_description" class="form-label">网站描述</label>
                        <textarea class="form-control" id="site_description" name="site_description" rows="3">{{ settings.site_description if settings else '专业的潜水培训与体验中心' }}</textarea>
                    </div>
                    <div class="mb-3">
                        <label for="contact_email" class="form-label">联系邮箱</label>
                        <input type="email" class="form-control" id="contact_email" name="contact_email" value="{{ settings.contact_email if settings else 'contact@theonediveclub.com' }}">
                    </div>
                    <div class="mb-3">
                        <label for="contact_phone" class="form-label">联系电话</label>
                        <input type="text" class="form-control" id="contact_phone" name="contact_phone" value="{{ settings.contact_phone if settings else '123-456-7890' }}">
                    </div>
                    <div class="mb-3">
                        <label for="address" class="form-label">地址</label>
                        <input type="text" class="form-control" id="address" name="address" value="{{ settings.address if settings else '广东省深圳市南山区' }}">
                    </div>
                    <div class="mb-3">
                        <label for="logo" class="form-label">网站Logo</label>
                        <input type="file" class="form-control" id="logo" name="logo">
                        {% if settings and settings.logo %}
                        <div class="mt-2">
                            <img src="{{ url_for('static', filename='uploads/' + settings.logo) }}" alt="网站Logo" class="img-thumbnail" style="max-height: 100px;">
                        </div>
                        {% endif %}
                    </div>
                    <button type="submit" class="btn btn-primary">保存设置</button>
                </form>
            </div>
        </div>
    </div>
    
    <div class="col-md-6">
        <div class="card mb-4">
            <div class="card-header">
                <h5 class="mb-0">社交媒体设置</h5>
            </div>
            <div class="card-body">
                <form method="post" action="{{ url_for('main.admin_update_social') }}">
                    <div class="mb-3">
                        <label for="wechat" class="form-label">微信公众号</label>
                        <input type="text" class="form-control" id="wechat" name="wechat" value="{{ settings.wechat if settings else '' }}">
                    </div>
                    <div class="mb-3">
                        <label for="weibo" class="form-label">微博</label>
                        <input type="text" class="form-control" id="weibo" name="weibo" value="{{ settings.weibo if settings else '' }}">
                    </div>
                    <div class="mb-3">
                        <label for="douyin" class="form-label">抖音</label>
                        <input type="text" class="form-control" id="douyin" name="douyin" value="{{ settings.douyin if settings else '' }}">
                    </div>
                    <div class="mb-3">
                        <label for="xiaohongshu" class="form-label">小红书</label>
                        <input type="text" class="form-control" id="xiaohongshu" name="xiaohongshu" value="{{ settings.xiaohongshu if settings else '' }}">
                    </div>
                    <button type="submit" class="btn btn-primary">保存设置</button>
                </form>
            </div>
        </div>
        
        <div class="card">
            <div class="card-header">
                <h5 class="mb-0">SEO设置</h5>
            </div>
            <div class="card-body">
                <form method="post" action="{{ url_for('main.admin_update_seo') }}">
                    <div class="mb-3">
                        <label for="meta_keywords" class="form-label">Meta关键词</label>
                        <input type="text" class="form-control" id="meta_keywords" name="meta_keywords" value="{{ settings.meta_keywords if settings else '潜水,潜水培训,潜水考证,深圳潜水' }}">
                        <div class="form-text">多个关键词用逗号分隔</div>
                    </div>
                    <div class="mb-3">
                        <label for="meta_description" class="form-label">Meta描述</label>
                        <textarea class="form-control" id="meta_description" name="meta_description" rows="3">{{ settings.meta_description if settings else '万岛潜水是深圳专业的潜水培训与体验中心，提供PADI潜水课程、体验潜水和潜水旅行服务。' }}</textarea>
                    </div>
                    <div class="mb-3">
                        <label for="baidu_analytics" class="form-label">百度统计代码</label>
                        <textarea class="form-control" id="baidu_analytics" name="baidu_analytics" rows="3">{{ settings.baidu_analytics if settings else '' }}</textarea>
                    </div>
                    <button type="submit" class="btn btn-primary">保存设置</button>
                </form>
            </div>
        </div>
    </div>
</div>

<div class="row mt-4">
    <div class="col-12">
        <div class="card">
            <div class="card-header">
                <h5 class="mb-0">系统设置</h5>
            </div>
            <div class="card-body">
                <form method="post" action="{{ url_for('main.admin_update_system') }}">
                    <div class="row">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label for="maintenance_mode" class="form-label">维护模式</label>
                                <div class="form-check form-switch">
                                    <input class="form-check-input" type="checkbox" id="maintenance_mode" name="maintenance_mode" {% if settings and settings.maintenance_mode %}checked{% endif %}>
                                    <label class="form-check-label" for="maintenance_mode">启用维护模式</label>
                                </div>
                                <div class="form-text">启用后，普通用户将无法访问网站</div>
                            </div>
                            <div class="mb-3">
                                <label for="maintenance_message" class="form-label">维护信息</label>
                                <textarea class="form-control" id="maintenance_message" name="maintenance_message" rows="3">{{ settings.maintenance_message if settings else '网站正在维护中，请稍后再来...' }}</textarea>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label for="booking_enabled" class="form-label">预约功能</label>
                                <div class="form-check form-switch">
                                    <input class="form-check-input" type="checkbox" id="booking_enabled" name="booking_enabled" {% if not settings or settings.booking_enabled %}checked{% endif %}>
                                    <label class="form-check-label" for="booking_enabled">启用预约功能</label>
                                </div>
                            </div>
                            <div class="mb-3">
                                <label for="max_bookings_per_day" class="form-label">每日最大预约数</label>
                                <input type="number" class="form-control" id="max_bookings_per_day" name="max_bookings_per_day" value="{{ settings.max_bookings_per_day if settings else 10 }}" min="1">
                            </div>
                        </div>
                    </div>
                    <button type="submit" class="btn btn-primary">保存设置</button>
                </form>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block scripts %}
<script>
    document.addEventListener('DOMContentLoaded', function() {
        // 表单提交前确认
        const forms = document.querySelectorAll('form');
        forms.forEach(form => {
            form.addEventListener('submit', function(e) {
                const confirmMsg = '确定要保存这些设置吗？';
                if (!confirm(confirmMsg)) {
                    e.preventDefault();
                }
            });
        });
    });
</script>
{% endblock %} 